package com.hm.business.shorturl.mapper;

import com.hm.business.shorturl.domain.ShortUrlDTO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* @Description: TODO
* @param
* @return
* @throws
* @author Coder编程
* @date 2021/6/16 9:58
*/
@Mapper
@Component
public interface ShortUrlMapper {

    /**
     * 从数据库查询短链
     *
     * @param shortUrl   短链,出去域名部分
     * @param dbShare    分库标志
     * @param tableShare 分表标志
     * @return
     */
    @Select({"select * from t_short_url  where short_url = #{shortUrl} and db_share = #{dbShare}  and table_share = #{tableShare} and active_state=1 and expiration_date>now()"})
    ShortUrlDTO queryUrl(String shortUrl, Integer dbShare, Long tableShare);

    /**
     * 插入短链
     *
     * @param shortUrlDTO parameter
     * @return result
     */
    @Insert({"insert into t_short_url(`long_url`,`short_url`, `code`, `expiration_date`, `active_state`,`tag`, `channel_name`, `device_type`, `create_date`, `update_date`,`db_share`, `table_share`) "
            + "values(#{longUrl}, #{shortUrl}, #{code}, #{expirationDate}, #{activeState}, #{tag}, #{channelName}, #{deviceType},now(),now(),#{dbShare}, #{tableShare})"})
    int insert(ShortUrlDTO shortUrlDTO);


}
